<script setup lang="ts">

export interface Config {
  id: number;
  key: string;
  value: string;
  description: string;
  created_at: string;
  updated_at: string;
}

defineProps<{
  configs: Config[];
  loading: boolean;
  error: string;
}>();

const emit = defineEmits<{
  (e: 'update', config: Config): void;
}>();

const handleUpdate = (config: Config) => {
  emit('update', config);
};
</script>

<template>
  <div class="config-management">
    <h2>配置管理</h2>
    <div v-if="loading">加载中...</div>
    <div v-else-if="error" class="error">{{ error }}</div>
    <div v-else>
      <table>
        <thead>
          <tr>
            <th>配置项</th>
            <th>值</th>
            <th>描述</th>
            <th>操作</th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="config in configs" :key="config.id">
            <td>{{ config.key }}</td>
            <td>{{ config.value }}</td>
            <td>{{ config.description }}</td>
            <td>
              <button 
                @click="handleUpdate(config)" 
                class="btn-edit"
              >
                编辑
              </button>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</template>

<style scoped>
.config-management {
  margin: 20px 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
}

th, td {
  padding: 10px;
  text-align: left;
  border-bottom: 1px solid #ddd;
}

th {
  background-color: #f5f5f5;
}

.btn-edit {
  background-color: #2196F3;
  color: white;
  border: none;
  padding: 5px 10px;
  cursor: pointer;
}

.error {
  color: #f44336;
  margin-bottom: 15px;
}
</style>